package demo.java.sql.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import demo.java.sql.service.DataValidService;
import demo.java.sql.service.TableEncryptService;

/**
 * approve_extend_info
 * 
 * @author hanjy
 *
 */
public class CallLogEncryptJob implements Runnable {

    private static Logger logger = LoggerFactory.getLogger(CallLogEncryptJob.class);

    private String srcSql = "select user_name,update_at,id from call_log  limit ?,?";

    private String bakSql = "select user_name,update_at,id from call_log_bak limit ?,?";

    private String updateSql = "update call_log set user_name=?,update_at=? where id=?";

    private TableEncryptService encryptService;

    public CallLogEncryptJob(TableEncryptService encryptService, DataValidService validService) {
        super();
        this.encryptService = encryptService;
        this.validService = validService;
    }

    private DataValidService validService;

    @Override
    public void run() {
        long t1 = System.currentTimeMillis();
        encryptService.encryptTableData(srcSql, updateSql, 10_000, new int[] { 0 });
        long t2 = System.currentTimeMillis();
        logger.info("加密作业耗时 {} ms.", (t2 - t1));
        try {
            validService.verifyAllData(srcSql, bakSql, 10_000, new int[] { 0 });
        } catch (Exception e) {
            logger.error("加密校验异常", e);
        }
        logger.info("数据校验作业耗时 {} ms.", (System.currentTimeMillis() - t2));
    }

}
